package com.ttt.config;

import com.alibaba.cloud.ai.dashscope.api.DashScopeApi;
import com.alibaba.cloud.ai.dashscope.rag.DashScopeDocumentRetriever;
import com.alibaba.cloud.ai.dashscope.rag.DashScopeDocumentRetrieverOptions;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.client.advisor.SimpleLoggerAdvisor;
import org.springframework.ai.rag.retrieval.search.DocumentRetriever;
import org.springframework.ai.zhipuai.ZhiPuAiChatModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class AIConfig {
    @Autowired
    private ZhiPuAiChatModel zhiPuAiChatModel;
    /**
     * 配置智普AI
     * @return ChatClient
     */
    @Bean
    public ChatClient chatClient(){
        return ChatClient.builder(zhiPuAiChatModel)
                .defaultSystem("你是一个PCB技术与实现方面以及检测方面世界级专家，注意你的言辞、态度")
                .defaultAdvisors(new SimpleLoggerAdvisor())
                .build();
    }
    /**
     * 注册知识库
     */
    @Bean
    public DocumentRetriever documentRetriever(){
        return  new DashScopeDocumentRetriever(new DashScopeApi("sk-1d62baeeac43447b92fe4279440bf883"),
                DashScopeDocumentRetrieverOptions.builder().withIndexName("smat_base").build());
    }
}